package com.codedog.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.codedog.constant.*;
import com.codedog.entity.Record;
import com.codedog.entity.*;
import com.codedog.entity.properties.CompletionRate;
import com.codedog.service.CodeDogService;
import com.codedog.utils.CodeDogExcelUtil;
import com.codedog.utils.CodeDogHTTPUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;


@Service(BeanNameConstant.CODEDOG_SERVICE)
public class CodeDogServiceImpl implements CodeDogService {

    @Autowired
    private CompletionRate completionRate;


    /**
     * 获取班级列表信息
     */
//    @Override
//    public void getLessonRecordsByClass() throws Exception {
//        String cookie = completionRate.getCookie();
//
//        //获取teacherid
//        UserInfo userInfo = CodeDogHTTPUtil.getUserInfo(cookie);
//        Integer internalTeacherId = userInfo.getId();
//
//        //根据teacherid获取campId
//        HttpRequest get = CodeDogHTTPUtil.createGet(UrlConstant.CPP_GETCAMPINFO_URL.replace("{internalTeacherId}", StrUtil.toString(internalTeacherId)).replace("{date}", StrUtil.toString(DateUtil.date())), cookie);
//        String responseStr = get.execute().body();
//        CPPCampInfo campInfo = JSONUtil.toBean(JSONUtil.toJsonStr(responseStr), CPPCampInfo.class);
//        Integer campId = campInfo.getData().get(0).getCampId();
//
//        //根据teacherID获取所有班级
//        get = CodeDogHTTPUtil.createGet(UrlConstant.CPP_GETCAMPINFO_BY_CAMID_URL.replace("{campId}", StrUtil.toString(campId)).replace("{internalTeacherId}", StrUtil.toString(internalTeacherId)).replace("{date}", StrUtil.toString(DateUtil.date())), cookie);
//        responseStr = get.execute().body();
//        CPPCampInfoByCampId campInfoByCampId = JSONUtil.toBean(JSONUtil.toJsonStr(responseStr), CPPCampInfoByCampId.class);
//        List<CPPCampInfoByCampId.LiveClassInfoBaseRespList> liveClassInfoBaseRespList = campInfoByCampId.getData().getLiveClassInfoBaseRespList();
//        List<Integer> classIdList = new ArrayList<>();
//        for (CPPCampInfoByCampId.LiveClassInfoBaseRespList classInfoBaseRespList : liveClassInfoBaseRespList) {
//            classIdList.add(classInfoBaseRespList.getClassId());
//        }
//        //根据班级ID获取lessonId
//        get = CodeDogHTTPUtil.createGet(UrlConstant.CPP_LESSONS_LIST_URL.replace("{classId}", StrUtil.toString(classIdList.get(0))), cookie);
//        responseStr = get.execute().body();
//        CPPLessons lessons = JSONUtil.toBean(JSONUtil.toJsonStr(responseStr), CPPLessons.class);
//        List<CPPLessons.CPPLesson> cppLessons = lessons.getData();
//        Integer lessonId = 0;
//        for (CPPLessons.CPPLesson cppLesson : cppLessons) {
//            if (cppLesson.getState().equals(CPPLessonStateConstant.END)) {
//                lessonId = cppLesson.getId();
//            }
//        }
//        get = CodeDogHTTPUtil.createGet(UrlConstant.CPP_GET_STEPID_URL.replace("{lessonId}", StrUtil.toString(lessonId)), cookie);
//        responseStr = get.execute().body();
//        CPPStep steps = JSONUtil.toBean(JSONUtil.toJsonStr(responseStr), CPPStep.class);
//        List<CPPStep.CPPStepDataStep> stepList = steps.getData().get(0).getStepList();
//        List<String> stepIdList = new ArrayList<>();
//        for (CPPStep.CPPStepDataStep cppStepDataStep : stepList) {
//            if (cppStepDataStep.getType().equals(CPPStepTypeConstant.NORMAL)) {
//                stepIdList.add(cppStepDataStep.getId());
//            }
//        }
//        get = CodeDogHTTPUtil.createGet(UrlConstant.CPP_WORKS_STATISTICS_URL.replace("{lessonId}", StrUtil.toString(lessonId)).replace("{stepId}", stepIdList.get(0)), cookie);
//        responseStr = get.execute().body();
//        CPPWork works = JSONUtil.toBean(JSONUtil.toJsonStr(responseStr), CPPWork.class);
//        System.out.println(JSONUtil.toJsonStr(works));
//    }

    /**
     * 获取班级列表信息
     */
    @Override
    public void getLessonRecordsByClass() throws Exception {
        /**
         * 1.发送请求，获取所有班级
         * 2.根据班级查询所有学生
         * 3.根据学生ID循环查询作业情况
         */
        String cookie = completionRate.getCookie();
        List<Record> records = getServingAndEndRecords(cookie);
        Integer serialNumber = 1;
        //获取班级Id根据班级查询学生列表
        for (Record record : records) {
            Integer classId = record.getId();
            String className = record.getName();
            if (record.getClassState().getName().equals(ClassStateConstant.CLASS_STATE_END) && !record.getUpgradeClass().isBlank()) {
//                className += FileTypeConstant.CLASS_STATE_END_SUFFIX;
                continue;
            }
            StudentListRequest studentListRequest = new StudentListRequest(classId);
            HttpRequest studentListRequestPost = CodeDogHTTPUtil.getPostNotBody(UrlConstant.STUDENT_LIST_URL, cookie);
            String studentListResponseStr = studentListRequestPost.body(JSONUtil.toJsonStr(studentListRequest)).execute().body();
            StudentListResponse studentListResponse = JSONUtil.toBean(studentListResponseStr, StudentListResponse.class);
            List<Student> studentList = studentListResponse.getData();
            ArrayList<Map<String, Object>> rows = new ArrayList<>();
            for (Student student : studentList) {
                if (student.getAttendancePlanState().equals(OptionConstant.ATTENDANCE_PLAN_STATE_READING) || student.getAttendancePlanState().equals(OptionConstant.ATTENDANCE_PLAN_STATE_CLOSED)) {
                    completionRate.setIsRecord(true);
                    Map<String, Object> homeWorkMap = getHomeWorkByStudentIdAndSerialNumber(student.getUserId(), student.getFullName(), cookie, serialNumber);
                    if (null != homeWorkMap) {
                        rows.add(homeWorkMap);
                        serialNumber++;
                    }
                } else {
//                    System.out.println(student.getFullName() + (student.getAttendancePlanState().equals(OptionConstant.ATTENDANCE_PLAN_STATE_REFUNDS) ? "-已退费" : "-已停课"));
                    System.out.println(student.getFullName() + "-已退费");
                }
            }
            if (completionRate.getIsRecord()) {
                rows.add(getCompletionRate(studentList.size()));
            }
            if (completionRate.getIsAdmin()) {
                CodeDogExcelUtil.updateAdminRows(rows, serialNumber);
            }
//            CodeDogExcelUtil.writeExcelByDate(CollUtil.newArrayList(rows), className + FileTypeConstant.EXCEL_ADD_SUFFIX + FileTypeConstant.EXCEL_SUFFIX);
            CodeDogExcelUtil.updateExcelRowBackgroundColor(CollUtil.newArrayList(rows), className + FileTypeConstant.EXCEL_ADD_SUFFIX + FileTypeConstant.EXCEL_SUFFIX);
            serialNumber = 1;
        }
    }

    @Override
    public void getLessonRecordsByDateOrTimeSlot(String inputStr) throws Exception {
        //年月日
        String str = StrUtil.subPre(inputStr, 8);
        str += "0000";
        DateTime parse = DateUtil.parse(str, new SimpleDateFormat("yyyyMMddHHmm"));
        String startOfDay = dateToStamp(str);
        String cookie = completionRate.getCookie();
        HttpRequest get = CodeDogHTTPUtil.createGet(UrlConstant.SCHEDULE_URL + startOfDay, cookie);
        String body = get.execute().body();
        List<Schedule> scheduleList = JSONUtil.toList(body, Schedule.class);
        ArrayList<Map<String, Object>> rows = new ArrayList<>();
        for (Schedule schedule : scheduleList) {
            if (dateToStamp(inputStr).equals(StrUtil.toString(schedule.getTime_slot()))) {
                List<Allocation> allocations = schedule.getAllocations();
                for (Allocation allocation : allocations) {
                    Map<String, Object> row = getHomeWorkByStudentId(allocation.getUser_id(), allocation.getFullname(), cookie);
                    rows.add(row);
                }
            }
        }
        if (completionRate.getIsRecord()) {
            rows.add(getCompletionRate(scheduleList.size()));
        }
        CodeDogExcelUtil.updateExcelRowBackgroundColor(CollUtil.newArrayList(rows), inputStr + FileTypeConstant.EXCEL_ADD_SUFFIX + FileTypeConstant.EXCEL_SUFFIX);
    }

    @Override
    public void getPerformance() throws Exception {
        /**
         * 1.发送请求，获取所有班级
         * 2.根据班级查询所有学生
         * 3.根据学生ID循环查询作业情况
         */
        String cookie = completionRate.getCookie();
        List<Record> records = getServingRecords(cookie);
        List<Map<String, Object>> rows = new ArrayList<>();
        Integer studentTotal = 0;
        //获取班级Id根据班级查询学生列表
        for (Record record : records) {
            Integer classId = record.getId();
            StudentListRequest studentListRequest = new StudentListRequest(classId);
            HttpRequest studentListRequestPost = CodeDogHTTPUtil.getPostNotBody(UrlConstant.STUDENT_LIST_URL, cookie);
            String studentListResponseStr = studentListRequestPost.body(JSONUtil.toJsonStr(studentListRequest)).execute().body();
            StudentListResponse studentListResponse = JSONUtil.toBean(studentListResponseStr, StudentListResponse.class);
            List<Student> studentList = studentListResponse.getData();
            studentTotal += studentList.size();
            for (Student student : studentList) {
                if (student.getAttendancePlanState().equals(OptionConstant.ATTENDANCE_PLAN_STATE_READING) || student.getAttendancePlanState().equals(OptionConstant.ATTENDANCE_PLAN_STATE_CLOSED)) {
                    completionRate.setIsRecord(true);
                    Map<String, Object> homeWorkMap = getHomeWorkByStudentId(student.getUserId(), student.getFullName(), cookie);
                    if (null != homeWorkMap) {
                        rows.add(homeWorkMap);
                    }
                } else {
//                    System.out.println(student.getFullName() + (student.getAttendancePlanState().equals(OptionConstant.ATTENDANCE_PLAN_STATE_REFUNDS) ? "-已退费" : "-已停课"));
                    System.out.println(student.getFullName() + "-已退费");
                }
            }
        }
        if (completionRate.getIsRecord()) {
            rows.add(getCompletionRate(studentTotal));
        }
        CodeDogExcelUtil.writeExcelByDate(CollUtil.newArrayList(rows), "汇总数据" + FileTypeConstant.EXCEL_SUFFIX);
    }

    @Override
    public void getLessonPaperReports() throws Exception {
        /**
         * 1.发送请求，获取所有班级
         * 2.根据班级查询所有学生
         * 3.根据学生ID循环查询作业情况
         */
        String cookie = completionRate.getCookie();
        List<Record> records = getServingRecords(cookie);
        //获取班级Id根据班级查询学生列表
        for (Record record : records) {
            Integer classId = record.getId();
            String className = record.getName();
            StudentListRequest studentListRequest = new StudentListRequest(classId);
            HttpRequest studentListRequestPost = CodeDogHTTPUtil.getPostNotBody(UrlConstant.STUDENT_LIST_URL, cookie);
            String studentListResponseStr = studentListRequestPost.body(JSONUtil.toJsonStr(studentListRequest)).execute().body();
            StudentListResponse studentListResponse = JSONUtil.toBean(studentListResponseStr, StudentListResponse.class);
            List<Student> studentList = studentListResponse.getData();
            ArrayList<Map<String, Object>> rows = new ArrayList<>();
            for (Student student : studentList) {
                if (student.getAttendancePlanState().equals(OptionConstant.ATTENDANCE_PLAN_STATE_READING) || student.getAttendancePlanState().equals(OptionConstant.ATTENDANCE_PLAN_STATE_CLOSED)) {
                    completionRate.setIsRecord(true);
                    getStageTestByStudentId(rows, student.getUserId(), student.getFullName(), cookie);
                }
            }
//            CodeMaoExcelUtil.writeAndMergeExcel(CollUtil.newArrayList(rows), className + FileTypeConstant.STAGE_TEST_SUFFIX + FileTypeConstant.EXCEL_SUFFIX);
            CodeDogExcelUtil.writeExcelByDate(CollUtil.newArrayList(rows), className + FileTypeConstant.STAGE_TEST_SUFFIX + FileTypeConstant.EXCEL_SUFFIX);
        }
    }

    private void getStageTestByStudentId(ArrayList<Map<String, Object>> rows, Long userId, String studentName, String cookie) {
        HttpRequest post = CodeDogHTTPUtil.getPost(UrlConstant.STAGE_TEST_URL, cookie);
        StageTestRequest stageTestRequest = new StageTestRequest(userId, OptionConstant.STAGETEST_OPTION_COMPLETE_STATUS);
        String body = post.body(JSONUtil.toJsonStr(stageTestRequest)).execute().body();
        StageTestResponse stageTestResponse = JSONUtil.toBean(body, StageTestResponse.class);
        if (stageTestResponse.getSuccess()) {
            List<StageTestResponseDataRecords> records = stageTestResponse.getData().getRecords();
            for (StageTestResponseDataRecords record : records) {
                Map<String, Object> row = new LinkedHashMap<>();
                row.put(ExcelTitleConstant.TITLE_ID, userId);
                row.put(ExcelTitleConstant.TITLE_USERNAME, studentName);
//              row.put(ExcelTitleConstant.PAPER_ID, record.getPaperId());
                row.put(ExcelTitleConstant.PAPER_NAME, record.getPaperName());
                row.put(ExcelTitleConstant.PAPER_POINT_CARD_NAME, record.getPaperPointCardName());
//              row.put(ExcelTitleConstant.PAPER_RECOR_FINISH_TIME, record.getPaperRecorFinishTime());
                row.put(ExcelTitleConstant.PAPER_RECORD_RESULT, record.getPaperRecordResult());
                rows.add(row);
            }
        }
    }

    /**
     * 统计完成率
     *
     * @param size
     * @return
     */
    private Map<String, Object> getCompletionRate(Integer size) {
        completionRate.setStudentTotal(size);
        Map<String, Object> row = new HashMap<>();
        row.put(ExcelTitleConstant.TITLE_ID, ExcelTitleConstant.COMPLETION_RATE);
        row.put(ExcelTitleConstant.TITLE_USERNAME, "");
        row.put(ExcelTitleConstant.TITLE_LESSON_NAME, "");
        row.put(ExcelTitleConstant.TITLE_XSND, NumberUtil.round(NumberUtil.mul(NumberUtil.div(completionRate.getTobStatusDone(), completionRate.getStudentTotal()), 100), 2) + "%");
        row.put(ExcelTitleConstant.TITLE_TZCZ, NumberUtil.round(NumberUtil.mul(NumberUtil.div(completionRate.getHomeworkStatusDone(), completionRate.getStudentTotal()), 100), 2) + "%");
        row.put(ExcelTitleConstant.TITLE_ZYDP, "");
        row.put(ExcelTitleConstant.TITLE_SJKYYZB, "");
        row.put(ExcelTitleConstant.TITLE_BYYYZB, NumberUtil.round(NumberUtil.mul(NumberUtil.div(completionRate.getVoiceWeeklyStatusDone(), completionRate.getStudentTotal()), 100), 2) + "%");
        completionRate.initCompletionRate();
        return row;
    }


    private Map<String, Object> getHomeWorkByStudentIdAndSerialNumber(Long studentId, String studentName, String cookie, Integer serialNumber) {
        Map<String, Object> row = new LinkedHashMap<>();
        row.put(ExcelTitleConstant.TITLE_ID, studentId);
        row.put(ExcelTitleConstant.TITLE_SERIAL_NUMBER, serialNumber);
        row.put(ExcelTitleConstant.TITLE_USERNAME, studentName);
        HttpRequest post = CodeDogHTTPUtil.getPost(UrlConstant.PREFIX + studentId + UrlConstant.SUFFIX, cookie);
        String body = post.execute().body();
        HomeWork homeWork = JSONUtil.toBean(body, HomeWork.class);
        List<HomeWorkRecordDetail> homeWorkRecordDetailList = homeWork.getWork_record_details();
        updateRow(row, homeWorkRecordDetailList, studentId, studentName);
        return row;
    }

    private Map<String, Object> getHomeWorkByStudentId(Long studentId, String studentName, String cookie) {
        Map<String, Object> row = new LinkedHashMap<>();
        row.put(ExcelTitleConstant.TITLE_ID, studentId);
        row.put(ExcelTitleConstant.TITLE_USERNAME, studentName);
        HttpRequest post = CodeDogHTTPUtil.getPost(UrlConstant.PREFIX + studentId + UrlConstant.SUFFIX, cookie);
        String body = post.execute().body();
        HomeWork homeWork = JSONUtil.toBean(body, HomeWork.class);
        List<HomeWorkRecordDetail> homeWorkRecordDetailList = homeWork.getWork_record_details();
        updateRow(row, homeWorkRecordDetailList, studentId, studentName);
        return row;
    }

    private void updateRow(Map<String, Object> row, List<HomeWorkRecordDetail> homeWorkRecordDetailList, Long studentId, String studentName) {
        HomeWorkRecordDetail homeWorkRecordDetail = null;
        if (null != homeWorkRecordDetailList && homeWorkRecordDetailList.size() > 0) {
            homeWorkRecordDetail = homeWorkRecordDetailList.get(0);
            row.put(ExcelTitleConstant.TITLE_LESSON_NAME, homeWorkRecordDetail.getPoint_description());
            //课后闯关
            String tobStatus = homeWorkRecordDetail.getTob_status();
            row.put(ExcelTitleConstant.TITLE_XSND, invertTobStatus(tobStatus));
            //拓展创作
            String homeworkStatus = homeWorkRecordDetail.getHomework_status();
            row.put(ExcelTitleConstant.TITLE_TZCZ, invertHomeworkStatus(homeworkStatus));
            //作业点评
            String workStatus = homeWorkRecordDetail.getWork_status();
            row.put(ExcelTitleConstant.TITLE_ZYDP, workStatus);
            //语音周报
            Map<String, String> voiceWeeklyStatusMap = invertVoiceWeeklyStatus(StrUtil.toString(studentId));
            row.put(ExcelTitleConstant.TITLE_SJKYYZB, voiceWeeklyStatusMap.get("lastClass"));
            row.put(ExcelTitleConstant.TITLE_BYYYZB, voiceWeeklyStatusMap.get("month"));
            System.out.println(studentName + "-所有信息获取成功");
        } else {
            row.put(ExcelTitleConstant.TITLE_LESSON_NAME, "等待上课");
            //课后闯关
            row.put(ExcelTitleConstant.TITLE_XSND, "等待上课");
            //拓展创作
            row.put(ExcelTitleConstant.TITLE_TZCZ, "等待上课");
            //作业点评
            row.put(ExcelTitleConstant.TITLE_ZYDP, "等待上课");
            //语音周报
            row.put(ExcelTitleConstant.TITLE_SJKYYZB, "等待上课");
            row.put(ExcelTitleConstant.TITLE_BYYYZB, "等待上课");
            System.out.println(studentName + "-一节课没上过，所以信息为空");
        }
    }


    public List<Record> getServingAndEndRecords(String cookie) {
        UserInfo userInfo = CodeDogHTTPUtil.getUserInfo(cookie);
        if (userInfo.getFullname().equals(completionRate.getAdmin())) {
            completionRate.setIsAdmin(true);
        }
        HttpRequest classListRequestPost = CodeDogHTTPUtil.getPostNotBody(UrlConstant.CLASS_MANAGE_URL, cookie);
        ClassManageRequest classManageRequest = new ClassManageRequest(userInfo.getId(), ClassStateConstant.CLASS_STATE_END, ClassStateConstant.CLASS_STATE_SERVING);
        String responseBody = classListRequestPost.body(JSONUtil.toJsonStr(classManageRequest)).execute().body();
        ClassManageResponse classManageResponse = JSONUtil.toBean(responseBody, ClassManageResponse.class);
        ClassManageResponseData classManageResponseData = classManageResponse.getData();
        List<Record> records = classManageResponseData.getRecords();
        return records;
    }

    /**
     * 获取开营中的班级
     *
     * @param cookie
     * @return
     */
    public List<Record> getServingRecords(String cookie) {
        UserInfo userInfo = CodeDogHTTPUtil.getUserInfo(cookie);
        if (userInfo.getFullname().equals(completionRate.getAdmin())) {
            completionRate.setIsAdmin(true);
        }
        HttpRequest classListRequestPost = CodeDogHTTPUtil.getPostNotBody(UrlConstant.CLASS_MANAGE_URL, cookie);
        ClassManageRequest classManageRequest = new ClassManageRequest(userInfo.getId(), ClassStateConstant.CLASS_STATE_SERVING);
        String responseBody = classListRequestPost.body(JSONUtil.toJsonStr(classManageRequest)).execute().body();
        ClassManageResponse classManageResponse = JSONUtil.toBean(responseBody, ClassManageResponse.class);
        ClassManageResponseData classManageResponseData = classManageResponse.getData();
        List<Record> records = classManageResponseData.getRecords();
        return records;
    }


    /*
     * 将时间转换为时间戳
     */
    private String dateToStamp(String dateStr) throws ParseException {
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmm");
        Date date = simpleDateFormat.parse(dateStr);
        long ts = date.getTime() / 1000L;
        res = String.valueOf(ts);
        return res;
    }

    private void getStudentList() {
        List<Allocation> allocations = null;
        int hour = DateUtil.thisHour(true);
        List<Schedule> scheduleList = new ArrayList<>();
        for (Schedule schedule : scheduleList) {
            int scheduleHour = DateUtil.hour(DateUtil.date(schedule.getTime_slot() * 1000L), true);
            if (scheduleHour >= hour && scheduleHour < (hour + 2)) {
                allocations = schedule.getAllocations();
            }
        }
    }


    private Map<String, String> invertVoiceWeeklyStatus(String userId) {
        Map<String, String> voiceWeeklyStatusMap = new HashMap<>();
        List<VoiceWeeklyDataRecord> voiceWeeklyDetailList = getVoiceWeeklyDetail(userId);
        //本月的语音周报
        String voiceWeeklyDetailByMonth = getVoiceWeeklyDetailByMonth(voiceWeeklyDetailList);
        String voiceWeeklyDetailByLastClass = "";
        if (CollectionUtil.isEmpty(voiceWeeklyDetailList)) {
            voiceWeeklyDetailByLastClass = VoiceWeeklyStatusConstant.NOT_OPENED_CHINESE;
        } else {
            voiceWeeklyDetailByLastClass = getVoiceWeeklyDetailByLastClass(voiceWeeklyDetailList.get(0));
        }
        //上节课的语音周报
        voiceWeeklyStatusMap.put("lastClass", voiceWeeklyDetailByLastClass);
        voiceWeeklyStatusMap.put("month", voiceWeeklyDetailByMonth);
        return voiceWeeklyStatusMap;
    }


    private String invertHomeworkStatus(String homeworkStatus) {
        //return "待评价" === e || "已评价" === e ? N.a.createElement("span", null, "已提交") : e
        if (!homeworkStatus.equals(HomeWorkStatusConstant.HOMEWORK_STATUS_DONE01) && !homeworkStatus.equals(HomeWorkStatusConstant.HOMEWORK_STATUS_DONE02)) {
            return HomeWorkStatusConstant.HOMEWORK_STATUS_NOT;
        } else {
            completionRate.addHomeworkStatusDone();
            return HomeWorkStatusConstant.HOMEWORK_STATUS_DONE03;
        }
    }

    private String invertTobStatus(String tobStatus) {
        if (!tobStatus.equals(HomeWorkStatusConstant.TOB_STATUS_DONE)) {
            return HomeWorkStatusConstant.TOB_STATUS_NOT;
        } else {
            completionRate.addTobStatusDone();
            return HomeWorkStatusConstant.TOB_STATUS_DONE;
        }
    }

    private List<VoiceWeeklyDataRecord> getVoiceWeeklyDetail(String userId) {
        String cookie = completionRate.getCookie();
        if (StrUtil.isBlank(cookie)) {
            System.out.println("请设置Cookie");
        }
        HttpRequest post = CodeDogHTTPUtil.getPostNotBody(UrlConstant.VOICEWEEKLY_URL, cookie);
        VoiceWeeklyRequestBody requestBody = new VoiceWeeklyRequestBody(Integer.valueOf(userId));
        String result = post.body(JSONUtil.toJsonStr(requestBody)).execute().body();
        VoiceWeekly voiceWeekly = JSONUtil.toBean(result, VoiceWeekly.class);
        List<VoiceWeeklyDataRecord> records = voiceWeekly.getData().getRecords();
        //计算一个自然月以内，语音周报是否都收听了

        return records;
    }

    private String getVoiceWeeklyDetailByMonth(List<VoiceWeeklyDataRecord> records) {

        for (VoiceWeeklyDataRecord record : records) {
            int openMonth = DateUtil.month(DateUtil.date(record.getOpenAt() * 1000L));
            int reportMonth = DateUtil.month(DateUtil.date(record.getReportTime() * 1000L));
            int thisMonth = DateUtil.thisMonth();
            if (openMonth == thisMonth && reportMonth == thisMonth && VoiceWeeklyStatusConstant.OPENED.equals(record.getOpenState())) {
                completionRate.addVoiceWeeklyStatusDone();
                return VoiceWeeklyStatusConstant.OPENED_CHINESE;
            }
        }
        return VoiceWeeklyStatusConstant.NOT_OPENED_CHINESE;
    }

    private String getVoiceWeeklyDetailByLastClass(VoiceWeeklyDataRecord record) {
        String openState = record.getOpenState();
        if (VoiceWeeklyStatusConstant.OPENED.equals(openState)) {
            return VoiceWeeklyStatusConstant.OPENED_CHINESE;
        }
        if (VoiceWeeklyStatusConstant.NO_DATA.equals(openState)) {
            return VoiceWeeklyStatusConstant.NOT_VOICE_CHINESE;
        }
        return VoiceWeeklyStatusConstant.NOT_OPENED_CHINESE;
    }
}

